const MtmModel = require('../models/matchteams.js')

class MtmCtrl {

    async list() {
        let lst = await MtmModel.find();//.sort('eventId');
        return lst.map(m=>m.toJSON());
    }

    async create(MtmData) {
        let mt = new MtmModel(MtmData);
        mt = await mt.save();
        return mt.toJSON();
    }

    async retrieve(id) {
        let mt = await MtmModel.findById(id);
        return mt?mt.map(e=>e.toJSON()): null;
    }

    async upsert(id, MtmData) {
        MtmData.id = id;
        let mt = await MtmModel.upsert(id, MtmData);
        return mt.toJSON();
    }
    async removeById(id) {
        await MtmModel.removeById(id);
        return 1;
    }

    async find(filter)
    {
        let r = await MtmModel.find(filter);
        return r.map(e=>e.toJSON());
    }
}

module.exports = new MtmCtrl();